const Router = require('koa-router');
const authRoutes = require('./auth.routes');
const userRoutes = require('./user.routes');
const messageRoutes = require('./message.routes');
const studentRoutes = require('./student.routes');
const teacherRoutes = require('./teacher.routes');
const classRoutes = require('./class.routes');
const dormitoryRoutes = require('./dormitory.routes');
const gradeRoutes = require('./grade.routes');
const attendanceRoutes = require('./attendance.routes');

const router = new Router();

// API版本
const API_VERSION = 'v1';

// 根路径
router.get('/', (ctx) => {
  ctx.body = {
    success: true,
    message: '文本消息后端服务API',
    version: API_VERSION,
    timestamp: new Date().toISOString()
  };
});

// 健康检查
router.get('/health', (ctx) => {
  ctx.body = {
    success: true,
    status: 'healthy',
    timestamp: new Date().toISOString()
  };
});

// 注册路由
router.use(`/api/${API_VERSION}/auth`, authRoutes.routes(), authRoutes.allowedMethods());
router.use(`/api/${API_VERSION}/users`, userRoutes.routes(), userRoutes.allowedMethods());
router.use(`/api/${API_VERSION}/messages`, messageRoutes.routes(), messageRoutes.allowedMethods());
router.use(`/api/${API_VERSION}/students`, studentRoutes.routes(), studentRoutes.allowedMethods());
router.use(`/api/${API_VERSION}/teachers`, teacherRoutes.routes(), teacherRoutes.allowedMethods());
router.use(`/api/${API_VERSION}/classes`, classRoutes.routes(), classRoutes.allowedMethods());
router.use(`/api/${API_VERSION}/dormitories`, dormitoryRoutes.routes(), dormitoryRoutes.allowedMethods());
router.use(`/api/${API_VERSION}/grades`, gradeRoutes.routes(), gradeRoutes.allowedMethods());
router.use(`/api/${API_VERSION}/attendances`, attendanceRoutes.routes(), attendanceRoutes.allowedMethods());

module.exports = router;